/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2023/2/27 10:17
 * @Version 1.0
 */
package com.eight.controller;

import com.eight.dao.CarTypeDao;
import com.eight.pojo.TbCar;
import com.eight.service.CarInformationService;
import com.eight.vo.CarShopTypeVo;
import com.eight.vo.CarVo;
import com.eight.vo.ComResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

@RestController
@RequestMapping("/rent")
public class CarInformationController {

    @Autowired
    private CarInformationService carInformationService;

    @RequestMapping("/list")
    public ComResult list(@RequestBody CarVo carVo){
        return carInformationService.selectAllCar(carVo);
    }

    @RequestMapping("/insert")
    public ComResult insert(@RequestBody TbCar tbCar){
        return carInformationService.insertCar(tbCar);
    }

    @RequestMapping("/delete")
    public ComResult delete(int id){
        return carInformationService.deleteCar(id);

    }

    @RequestMapping("/update")
    public ComResult update(@RequestBody TbCar tbCar){
        return carInformationService.updateCar(tbCar);
    }

    @Autowired
    private CarTypeDao carTypeDao;

    /**
     * 查询车辆的类型和门店
     * @param shopId
     * @param type
     * @return
     */
    @RequestMapping("/selectByTypeShopId/{shopId}/{type}")
    public List<TbCar> selectByShopId(@PathVariable Integer shopId, @PathVariable Integer type){
        return carInformationService.selectByTypeShopId(shopId, type);
    }

    /**
     * 根据价格排序
     * @param carShopTypeVo
     * @return
     */
    @RequestMapping("/selectShopByType")
    public ComResult selectShopByType(@RequestBody CarShopTypeVo carShopTypeVo){
        List<TbCar> cars = carInformationService.selectShopByType(carShopTypeVo.getShopId(), carShopTypeVo.getType(), carShopTypeVo.getOr());
        return new ComResult(2000,"查询成功",cars);
    }




}

